﻿/*
 * Форма на которой размещается визуализатор АЧХ
 * */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ctem.samples.actors.concurrent
{
    public partial class AbsFFTForm : Form
    {
        public delegate void OnDataAppearingHandler(double[] data);
        OnDataAppearingHandler oda;
        public void SetArrayOfData(double[] data)
        {
            this.Invoke(oda,data);
        }

        private void TopMostToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.TopMost = !this.TopMost;
        }

         public void ReInitialize()
        {
            SignalChartBox1.Clear();
        }

        public AbsFFTForm(int N)
        {
            oda = new OnDataAppearingHandler(PrintBode);
            InitializeComponent();
            SignalChartBox1.IsLog = false;
            SignalChartBox1.CollapsSignal(true);
            SignalChartBox1.SetAxisCaption('x', "Частота", "1/сек");
            SignalChartBox1.SetAxisCaption('y', "Амплитуда", "");

            RealSetMagicNumberNInterval(N);
            SignalChartBox1.AddSeries(new ctem.gui.SignalChart.Series("АЧХ", Color.Black));
        }

        public delegate void SetMagicNumberNHandler(int N);
        SetMagicNumberNHandler rih;
        public void SetMagicNumberNInterval(int N)
        {
            this.Invoke(rih, N);
        }

        void RealSetMagicNumberNInterval(int N)
        {
            SignalChartBox1.SetMagicNumberN(N);
        }

        private void PrintBode(double[] data)
        {
            //signalChartBox1.AddSeries(new ctem.gui.SignalChart.Series("Bode", Color.Black));
            //signalChartBox1.RefreshInterval = data.Length;
            //for(int i=0;i<data.Length;i++)
            //        signalChartBox1.AddItem("Bode", new PointF((float)Math.Log10(i), (float)data[i]));

            
            
            for (int i = 1; i < data.Length; i++)
                SignalChartBox1.AddItem("АЧХ", new PointF(i, (float)data[i]));

                /*
                const int n = 5;
                signalChartBox1.AddSeries(new ctem.gui.SignalChart.Series("Bode", Color.Black));
                signalChartBox1.RefreshInterval = n;
                for (int i = 0; i < n; i++)
                    signalChartBox1.AddItem("Bode", new PointF(i, i));
                 * * */
        }
    }
}